
$(document).ready(function () {
    $("#form").steps({
        bodyTag: "fieldset",
        labels: {
            finish: "完成", // 修改按钮得文本
            next: "下一步", // 下一步按钮的文本
            previous: "上一步", // 上一步按钮的文本
            loading: "Loading ..."
        },
        onStepChanging: function (event, currentIndex, newIndex) {
            var valid = true
            // console.log(111)
            // alert("当前"+currentIndex)
            // alert("下页"+newIndex)
            // Always allow going backward even if the current step contains invalid fields!
            if (currentIndex > newIndex) {
                return true;
            }

            // Forbid suppressing "Warning" step if the user is to young
            if (newIndex === 3 && Number($("#age").val()) < 18) {
                return false;
            }

            var form = $(this);

            // Clean up if user went backward before
            if (currentIndex < newIndex) {
                // To remove error styles
                $(".body:eq(" + newIndex + ") label.error", form).remove();
                $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
            }

            // Disable validation on fields that are disabled or hidden.
            form.validate().settings.ignore = ":disabled,:hidden";


            return true

            // alert(form.valid())
            // return form.valid();

            // Start validation; Prevent going forward if false


        },
        onStepChanged: function (event, currentIndex, priorIndex) {

            // Suppress (skip) "Warning" step if the user is old enough.
            if (currentIndex === 2 && Number($("#age").val()) >= 18) {
                $(this).steps("下一个");
            }

            // Suppress (skip) "Warning" step if the user is old enough and wants to the previous step.
            if (currentIndex === 2 && priorIndex === 3) {
                $(this).steps("上一个");

            }
        },
        onFinishing: function (event, currentIndex) {

            // Disable validation on fields that are disabled.
            // At this point it's recommended to do an overall check (mean ignoring only disabled fields)
            // form.validate().settings.ignore = ":disabled";

            // Start validation; Prevent form submission if false
            return true;
        },
        onFinished: function (event, currentIndex) {
            // var form = $(this);
            history.back()
            // Submit form input
            // form.submit();
        }
    }).validate({
        errorPlacement: function (error, element) {
            element.after(error);
        },
        rules: {

        }, messages: {

        },
    });
});




addDiscountPolicy.init();
